cellrenderertoggle: Change "indicator-size" handling
authorBenjamin Otte <otte@redhat.com>
Tue, 16 Feb 2016 01:41:44 +0000 (02:41 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 16 Feb 2016 01:53:34 +0000 (02:53 +0100)
The following changes were done to (hopefully) achieve backwards
compatibility while allowing themes to change the size of the indicator.

(1) Deprecate the property.
(2) Change the default value of the property to 0. If it is not 0,
    use the property's value for the indicator size. This should make
    all programs that actually set it keep the size they set it to.
(3) If set to other values than 0, use min-width/min-height of the
    check/radio node to size the indicator. This allows themes to change
    the size.
(4) Fall back to the previous default size of 16px. This way themes that
    do not set the size keep the same behavior.

gtk/gtkcellrenderertoggle.c

index d2f4889e94ac9f55123efe6e825eb2987c6069a6..fcf82ab6694744c3117d219465c6b5750bdee12c 100644 (file)
@@ -115,7 +115,7 @@ gtk_cell_renderer_toggle_init (GtkCellRendererToggle *celltoggle)
   g_object_set (celltoggle, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
   gtk_cell_renderer_set_padding (GTK_CELL_RENDERER (celltoggle), 2, 2);
 
-  priv->indicator_size = TOGGLE_WIDTH;
+  priv->indicator_size = 0;
   priv->inconsistent = FALSE;
 }
 
@@ -171,8 +171,8 @@ gtk_cell_renderer_toggle_class_init (GtkCellRendererToggleClass *class)
                                                     P_("Size of check or radio indicator"),
                                                     0,
                                                     G_MAXINT,
-                                                    TOGGLE_WIDTH,
-                                                    GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+                                                    0,
+                                                    GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_DEPRECATED));
 
   
   /**
@@ -321,7 +321,30 @@ gtk_cell_renderer_toggle_save_context (GtkCellRenderer *cell,
 
   return context;
 }
-                              
+static void
+calc_indicator_size (GtkStyleContext *context,
+                     gint             indicator_size,
+                     gint            *width,
+                     gint            *height)
+{
+  if (indicator_size != 0)
+    {
+      *width = *height = indicator_size;
+      return;
+    }
+
+  gtk_style_context_get (context, gtk_style_context_get_state (context),
+                         "min-width", width,
+                         "min-height", height,
+                         NULL);
+
+  if (*width == 0)
+    *width = TOGGLE_WIDTH;
+  if (*height == 0)
+    *height = TOGGLE_WIDTH;
+}
+
 static void
 gtk_cell_renderer_toggle_get_size (GtkCellRenderer    *cell,
                                   GtkWidget          *widget,
@@ -346,8 +369,9 @@ gtk_cell_renderer_toggle_get_size (GtkCellRenderer    *cell,
   gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding);
   gtk_style_context_get_border (context, gtk_style_context_get_state (context), &border);
 
-  calc_width = xpad * 2 + priv->indicator_size + padding.left + padding.right + border.left + border.right;
-  calc_height = ypad * 2 + priv->indicator_size + padding.top + padding.bottom + border.top + border.bottom;
+  calc_indicator_size (context, priv->indicator_size, &calc_width, &calc_height);
+  calc_width += xpad * 2 + padding.left + padding.right + border.left + border.right;
+  calc_height += ypad * 2 + padding.top + padding.bottom + border.top + border.bottom;
 
   gtk_style_context_restore (context);